<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrappe">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="姓名">
              <j-input placeholder="请输入姓名" v-model="mostImportantParams.nickName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="人员类型">
              <j-dict-select-tag
                v-model="mostImportantParams.userType"
                dictCode="production_user_type"
                placeholder="请选择人员类型"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <!-- 根据权限决定按钮是否禁用 -->
    <!-- :disabled="isDisabledAuth('erpOmcPrepareProject:add')" -->
    <div class="table-operator">
      <a-button @click="addData" type="primary" icon="plus"> 新增 </a-button>
      <a-button
        type="primary"
        icon="download"
        @click="downloadXML"
        :loading="exportLoading"
      >导出</a-button>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item, index) in defColumns">
                <template v-if="item.key != 'rowIndex' && item.dataIndex != 'action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right">
          <a-icon type="setting" :style="iconStyle" />
        </a>
      </a-popover>
    </div>
    <!-- table区域-begin -->
    <a-table
      ref="table"
      size="middle"
      :scroll="{ x: scrollX }"
      :components="draggableComponent"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="{
        selectedRowKeys: selectedRowKeys,
        onChange: onSelectChange
      }"
      class="j-table-force-nowrap"
      :customRow="customRow"
      @change="handleTableChange"
    >
      <template slot="billNo" slot-scope="text, record">
        <span @click="clickBillNo(record)" style="color: #00aaf0; cursor: pointer">{{ text }}</span>
      </template>
      <span slot="action" slot-scope="text, record">
        <!-- 已统计，可以查看 -->
        <a-button type="link" @click="editData(record)"> 修改 </a-button>
        <!-- 未统计，可以撤回 -->
        <a-popconfirm title="确定删除吗?" @confirm="() => deleteData(record)">
          <a-button type="link">删除</a-button>
        </a-popconfirm>
      </span>
    </a-table>
    <simpleModal :title="modalTitle" @clickSubmit="clickSubmit" ref="simpleModal">
      <taskSpecialPersonModalVue :editParams="editParams" @submitSuccess="submitSuccess" ref="slotContent" :modalSlotStatus="modalSlotStatus"></taskSpecialPersonModalVue>
    </simpleModal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
// 根据权限来给一个布尔值，可用来控制是否禁用
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { deleteAction } from '@/api/manage'
import simpleModal from '@/components/simpleModal'
import taskSpecialPersonModalVue from './modules/taskSpecialPersonModal.vue'
import moment from "moment";
export default {
  name: 'index',
  mixins: [DisabledAuthFilterMixin, JeecgListMixin],
  components: {
    simpleModal,
    taskSpecialPersonModalVue
  },
  data() {
    return {
      type: '',
      isorter: {
        column: 'createTime',
        order: 'desc',
      },
      dictOptions: {},
      description: '工时填报列表',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          ellipsis: true,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '人员编号',
          align: 'center',
          dataIndex: 'empId_dictText',
          width: 390,
          ellipsis: true,
        },
        {
          title: '姓名',
          align: 'center',
          dataIndex: 'userId_dictText',
          width: 135,
          ellipsis: true,
        },
        {
          title: '所属部门',
          align: 'center',
          dataIndex: 'teamId_dictText',
          width: 300,
          ellipsis: true,
        },
        {
          title: '人员类型',
          align: 'center',
          dataIndex: 'userType_dictText',
          width: 520,
          ellipsis: true,
        },{
          title: '备注',
          align: 'center',
          dataIndex: 'remark',
          width: 520,
          ellipsis: true,
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 160,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action',
          },
        },
      ],
      url: {
        // 列表渲染
        list: '/api/erp/hours/personneltype/erpProductionPersonnelType/allList',
        delete:'/api/erp/hours/personneltype/erpProductionPersonnelType/delete',
        exportXlsUrl: '/api/erp/hours/personneltype/erpProductionPersonnelType/exportXls'
      },
      // 不会被其他查询条件覆盖的查询参数
      mostImportantParams: {
        fillInStatus: 'yes',
      },
      workingHours: [],
      modalSlotStatus: '',
      modalTitle: '新增',
      editParams:''
    }
  },
  created() {},
  methods: {
    // 自定义查询
    searchQuery() {
      this.onClearSelected()
      this.loadData(1)
    },
    // 下载
    downloadXML() {
      this.handleExportXls('工时特殊人员' + moment().format('YYYY-MM-DD HH:mm:ss'))
    },
    // 重置按钮
    searchReset() {
      this.mostImportantParams = {}
      this.workingHours = []
      this.loadData(1)
    },
    // 编辑按钮
    editData(record) {
      // 需要对照着子组件去设置子组件的status
      this.editParams = record.id
      this.handleModalSlotStatus('edit')
      this.modalTitle = '编辑'
    },
    // 删除按钮
    deleteData(record) {
      deleteAction(this.url.delete, { id: record.id }).then(res=>{
        if(res.success){
          this.$message.success('删除成功')
          this.loadData()
        }else{
          this.$message.error(res.message)
        }
      })
    },
    // 填报本周工时
    addData() {
      // 添加人员身份判断，如果是白名单，不需要填报
      // 添加数据判断，如果上周未填报，则提示先补填上周
      // 添加数据判断，如果本周已填报，则提示本周已填报
      this.handleModalSlotStatus('add')
    },
    // 子组件内容提交，关闭弹窗
    clickSubmit() {
      // 调用子组件提交方法
      this.$refs.slotContent.submitData()
    },
    // 点击打开弹窗，设置内部插槽的status
    // 重置modalTitle
    handleModalSlotStatus(status) {
      this.modalSlotStatus = status
      this.$refs.simpleModal.visible = true
      this.modalTitle = this.$options.data().modalTitle
    },
    // 内部成功提交
    submitSuccess() {
      this.$refs.simpleModal.visible = false
      this.loadData(1)
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
